 <!--
* description: 呆滞件查询_网点&总部
* author: chenjingwen
* createdDate: 2021-3-4
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-table-cols="tableCols"
      :dynamic-api-config="apiConfig"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-show-more-btn="true"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/templates/oneTable";
import { orgApis } from "@/api/paSparePartsManagement";
import Vue from "vue";
import { exportExcel } from '@/utils/getTimeString.js'

export default {
  name: "deadpartsinquiry",

  components: {
    OneTableTemplate,
    // Edit: () => import("./edit"),
  },

  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ""], function () {
      next();
    });
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path;

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode]);

    return {
      // 网格查询API配置对象
      apiConfig: orgApis.orderQueryData,
      editRowData: {},
      selectData: {},
      editPopupsVisible: false,

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey3",
          type: "primary",
          size: "small",
          name: "search",
          clickEvent: () => this.queryTable(1),
          text: this.$t("sys.button.query"), // 查询
          position: "right",
          fuzzySearch: true,
        },
        {
          compKey: "btnKey3",
          type: "primary",
          size: "small",
          name: "export",
          clickEvent: () => this.export(),
          text: this.$t("sys.button.export"), // 导出
          position: "right",
          fuzzySearch: true,
        },
        {
          compKey: "btnKey4",
          type: "",
          size: "small",
          name: "reset",
          clickEvent: () => this.reset(),
          text: this.$t("sys.button.reset"),
          position: "right", // 重置
        },
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
              .tableComponents
          : [
              {
                compKey: "compKey1",
                labelName: "网点编码:",
                codeField: "dlrCode",
                textField: "dlrCode",
                component: () => import("@/components/ve/salesStore"),
                type: "inputText",
                
                isMust: true,
                isMul: false,
                span: 6,
              },
              {
                compKey: "compKey2",
                labelName: "网点名称:",
                codeField: "dlrName",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
           
              {
                compKey: "compKey3",
                labelName: "仓库名称:",
                codeField: "warehouseName",
                component: () => import("@/components/org/commonSelect"),
                type: "dropdownList",
                textField: "warehouseId",
                customObj: {
                  api: orgApis.getWarehouse,
                  defOptionFields:['warehouseId','warehouseName']
                },
                isMul: false,
                isMust: true,
              },
             
              {
                compKey: "compKey4",
                labelName: "备件编码:",
                codeField: "partNo",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "compKey5",
                labelName: "备件名称:",
                codeField: "partName",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",

                isMul: false,
                isMust: false,
              },

              {
                compKey: "compKey6",
                labelName: "积压天数:",
                codeField: "backlogDays",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",

                isMul: false,
                isMust: false,
              },
              
            ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "subsidyId",
                label: "主键ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "updateControlId",
                label: "并发控制ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "dlrCode",
                label: "网点编码",
              },

              {
                prop: "dlrName",
                label: "网点名称",
              },
              {
                prop: "partNo",
                label: "备件编号",
              },
              {
                prop: "partName",
                label: "备件名称",
              },
              {
                prop: "carConfigIdList",
                label: "适用车型",
              },

              {
                prop: "accountQty",
                label: "账面库存",
              },
              {
                prop: "availableInventory",
                label: "可用库存",
              },
              {
                prop: "pointPriceTax",
                label: "成本价",
              },
              {
                prop: "inventoryAmount",
                label: "库存金额",
              },
              {
                prop: "lastIndate",
                label: "最新有效入库日期",
              },
              {
                prop: "lastOutdate",
                label: "最新有效出库日期",
              },
              {
                prop: "backlogDays",
                label: "积压天数",
              },
             
            ],

      // 表单数据
      formField: this.$utils.getFormField(
        this,
        {
          dlrCode: "",
          dlrName: "",
          warehouseName: "",
          partNo: "",
          partName: "",
          backlogDays: ""
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
    };
  },

  mounted() {
    // 列表查询
    this.queryTable(1);

    // this.$refs.multipleTable.list = [
    //   {
    //     index: 1,
    //   },
    // ];
  },

  methods: {
    edit(index) {
      this.editPopupsState = "edit";
      this.editPopupsVisible = true;
      this.editRowData = this.$refs["multipleTable"].list[index];
    },
    close() {
      this.editPopupsVisible = false;
      this.queryTable(1);
    },
    export(){
      exportExcel(this.formField, orgApis.orderQueryExport.APIUrl, orgApis.orderQueryExport.ServiceCode, '呆滞件查询_网点&总部')
    },
  },
};
</script>
